package com.tec.security.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.tec.security.service.AuditLogService;
import com.tec.security.utils.response.Result;
import com.tec.security.service.NewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "审核接口")
@RequestMapping("/Audit")
public class AuditController {
    private final NewsService adminnewsService;
    private final AuditLogService auditLogService;
    @Autowired
    public AuditController(NewsService adminnewsService, AuditLogService auditLogService) {
        this.adminnewsService = adminnewsService;
        this.auditLogService = auditLogService;
    }

    /**
     * @description 新闻审核接口
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "新闻通过审核")
    @PostMapping("/newsTo")
    public Result newsAudit(Integer id,String name){
        if(adminnewsService.newsAudit(id,name))
        {
            auditLogService.auditInfo(StpUtil.getLoginId().toString(),"通过审核","01");
            return Result.success("审核通过",null);
        }else{
            return Result.failure("审核失败",null);
        }
    }

    /**
     * @description 新闻驳回接口
     * @author 陆林
     * @date 2023-11-9
     */
    @ApiOperation(value = "新闻驳回审核")
    @PostMapping("/newsReturn")
    public Result newsNoAudit(Integer id,String name){
        if(adminnewsService.newNoAudit(id,name)){
            auditLogService.auditInfo(StpUtil.getLoginId().toString(),"驳回审核","02");
            return Result.success("驳回成功",null);
        }else{
            return Result.failure("驳回失败",null);
        }
    }

    /**
     * @description 新闻停用
     * @author 陆林
     * @date 2023-12-1
     */
    @ApiOperation(value = "新闻停用")
    @PostMapping("/Deactivated")
    public Result Deactivated(Integer id,String name){
        if(adminnewsService.newsDeactivated(id,name)){
            auditLogService.auditInfo(StpUtil.getLoginId().toString(),"新闻停用","03");
            return Result.success("停用成功",null);
        }else{
            return Result.failure("停用失败",null);
        }
    }

    /**
     * @description 新闻启用
     * @author 陆林
     * @date 2023-12-1
     */
    @ApiOperation(value = "新闻启用")
    @PostMapping("/Enable")
    public Result Enable(Integer id,String name){
        if(adminnewsService.newsEnable(id,name)){
            auditLogService.auditInfo(StpUtil.getLoginId().toString(),"新闻启用","04");
            return Result.success("启用成功",null);
        }else{
            return Result.failure("启用失败",null);
        }
    }
}
